<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>高性能外部JavaScript脚本文件的加载与执行</title>
</head>

<body>
<p style="color: #69F; text-align: center; font-size: 18px; font-weight: bold;">高性能外部JavaScript脚本文件的加载与执行</p>
<p>&lt;script type=&quot;text/javascript&quot;&gt;<br />
  //高性能外部JavaScript脚本文件的加载与执行<br />
  function loadScript(url, callback){<br />
  var script = document.createElement(&quot;script&quot;);<br />
  script.type = &quot;text/javascript&quot;;<br />
  script.src = url;<br />
  if (script.readyState){//IE<br />
  script.onreadystatechange = function(){<br />
  if (script.readyState == &quot;loaded&quot; || script.readyState == &quot;complete&quot;){<br />
  script.onreadystatechange = null;<br />
  callback();<br />
  }<br />
  };<br />
  }else{//非IE<br />
  script.onload = function(){<br />
  callback();<br />
  };<br />
  }<br />
  document.getElementsByTagName(&quot;head&quot;)[0].appendChild(script);<br />
  }<br />
&lt;/script&gt;</p>
<p>使用示例：</p>
<p>loadScript(&quot;file1.js&quot;, function(){<br />
loadScript(&quot;file2.js&quot;, function(){<br />
loadScript(&quot;file3.js&quot;, function(){<br />
alert(&quot;都已经加载完成!&quot;);<br />
});<br />
});<br />
});<br />
</p>
</body>
</html>
